package day20180408;

import java.sql.*;

public class selectClassTest {

    public static void main(String[] args) {

        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String sql = "select * from test1 where class = 1";

        try {

            Class.forName("com.mysql.jdbc.Driver");

            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/sctu_system_test?serverTimezone = UTC",
                    "root",
                    "123456");

            statement = connection.createStatement();
            resultSet = statement.executeQuery(sql);

            System.out.println("sno\tsname\tsex\tclasses\tgrade\tplace");
            while(resultSet.next()) {

                int sno = resultSet.getInt(2);
                String sname = resultSet.getString(3);
                String sex = resultSet.getString(7);
                String classes = resultSet.getString(4);
                float grade = resultSet.getFloat(5);
                String place = resultSet.getString(6);
                System.out.println(sno + "\t" + sname + "\t" + sex + "\t" + classes + "\t" + grade + "\t" + place);

            }


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            try {
                statement.close();
                resultSet.close();
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }

}
